// 立项表单
import OrgTreeSelect from '@/components/OrgTreeSelect'

export const assetNatureMap = new Map([[0, '可调拨'], [1, '利旧'], [2, '不可调拨'], [3, '可调拨/已转资产']])
export const assetStatusMap = new Map([[0, '在用'], [1, '闲置'], [2, '待定'], [3, '报废'], [4, '丢失']])
export const buyCatalogueMap = new Map([[0, '采购'], [1, '调拨']])
export const assetCatalogueMap = new Map([[0, '智慧展厅设备'], [1, '智慧工地设备'], [2, '其他']])
export const assetCatalogue = [
    {key: 0, label: '智慧展厅设备', value: '0'},
    {key: 1, label: '智慧工地设备', value: '1'},
    {key: 2, label: '其他', value: '2'},
]
export const buyCatalogue = [
    {key: 0, label: '采购', value: '0'},
    {key: 1, label: '调拨', value: '1'}
]
export const assetStatus = [
    {key: 0, label: '在用', value: '0'},
    {key: 1, label: '闲置', value: '1'},
    {key: 2, label: '待定', value: '2'},
    {key: 2, label: '报废', value: '3'},
    {key: 2, label: '丢失', value: '4'}
]

export const tabColumnsCreate = [
    {
        title: '序号',
        width: 65,
        scopedSlots: {customRender: 'serial'}
    },
    {
        title: '所属分公司',
        width: 300,
        dataIndex: 'branchName'
    },
    {
        title: '项目名称',
        width: 300,
        dataIndex: 'projectName'
    },
    {
        title: '智慧展厅立项时间',
        width: 300,
        dataIndex: 'setUpTime'
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: 120,
        fixed: 'right',
        scopedSlots: {customRender: 'operation'}
    }
]
export const tabColumnsManage = [
    {
        title: '序号',
        width: 80,
        align: 'center',
        dataIndex: 'index',
        fixed: 'left',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '资产编号',
        dataIndex: 'assetNumber',
        align: 'center',
        fixed: 'left',
        width: 150,
        // ellipsis: true,
        scopedSlots: {customRender: 'assetNumber'},
    },
    {
        title: '资产名称',
        dataIndex: 'assetName',
        align: 'center',
        width: 150,
        ellipsis: true,
        fixed: 'left'

    },
    {
        title: '品牌',
        dataIndex: 'brandName',
        align: 'right',
        width: 150,
        ellipsis: true
    },
    {
        title: '规格型号及技术参数',
        dataIndex: 'specification',
        width: 400,
        ellipsis: true
    },
    {
        title: '单位',
        dataIndex: 'unitName',
        align: 'center',
        width: 70,
        // ellipsis: true
    },
    {
        title: '价格(元)',
        dataIndex: 'unitPrice',
        align: 'center',
        width: 120,
        // ellipsis: true
    },
    {
        title: '所属单位',
        // align: 'center',
        width: 150,
        dataIndex: 'ownerBranchName',
        // ellipsis: true
    },
    {
        title: '所属项目',
        // align: 'center',
        dataIndex: 'ownerProjectName',
        width: 150,
        // ellipsis: true
    },
    {
        title: '使用项目',
        // align: 'center',
        dataIndex: 'currentProjectName',
        width: 150,
        // ellipsis: true
    },
    {
        title: '进场时间',
        dataIndex: 'enterTime',
        // ellipsis: true,
        align: 'center',
        width: 150,
        scopedSlots: {customRender: 'enterTime'}
    },

    {
        title: '资产状态',
        dataIndex: 'assetStatus',
        // ellipsis: true,
        width: 90,
        type: 'select',
        align: 'center',
        data: [...assetStatusMap.keys()].map((key) => {
            return {
                value: key,
                label: assetStatusMap.get(key)
            }
        }),
        options: [...assetStatusMap.keys()].map((key) => {
            return  assetStatusMap.get(key)
        }),
        scopedSlots: {customRender: 'assetStatus'},
        excelConfig: {
            dataValidation: {
                type: 'list'
            }
        }
    },
    {
        title: '资产类别',
        dataIndex: 'assetCatalogue',
        // ellipsis: true,
        align: 'center',
        width: 150,
        type: 'select',
        data: [...assetCatalogueMap.keys()].map((key) => {
            return {
                value: key,
                label: assetCatalogueMap.get(key)
            }
        }),
        options: [...assetCatalogueMap.keys()].map((key) => {
            return  assetCatalogueMap.get(key)
        }),
        scopedSlots: {customRender: 'assetCatalogue'},
        excelConfig: {
            dataValidation: {
                type: 'list'
            }
        }
    },
    {
        title: '购买类别',
        dataIndex: 'buyCatalogue',
        // ellipsis: true,
        width: 120,
        align: 'center',
        type: 'select',
        data: [...buyCatalogueMap.keys()].map((key) => {
            return {
                value: key,
                label: buyCatalogueMap.get(key)
            }
        }),
        options: [...buyCatalogueMap.keys()].map((key) => {
            return  buyCatalogueMap.get(key)
        }),
        scopedSlots: {customRender: 'buyCatalogue'},
        excelConfig: {
            dataValidation: {
                type: 'list'
            }
        }
    },

    {
        title: '调拨时间',
        dataIndex: 'allotTime',
        align: 'center',
        // ellipsis: true,
        width: 150,
        scopedSlots: {customRender: 'allotTime'}
    },
    {
        title: '调拨次数',
        dataIndex: 'allotCount',
        // ellipsis: true,
        width: 100,
        align: 'center'
    },
    {
        title: '报废/丢失时间',
        dataIndex: 'discardTime',
        align: 'center',
        width: 150,
        scopedSlots: {customRender: 'discardTime'},
    },
    {
        title: '供应商',
        dataIndex: 'supplierName',
        align: 'center',
        width: 120,
        ellipsis: true
    },
    {
        title: '保管人',
        dataIndex: 'keeperName',
        align: 'center',
        width: 80,
        ellipsis: true
    },

    {
        title: '操作',
        dataIndex: 'operation',
        align: 'center',
        fixed: 'right',
        width: 120,
        isHidden: true,
        scopedSlots: {customRender: 'operation'}
    }
]

// 可立项导入
export const tabColumnsImport = [
    {
        title: '序号',
        dataIndex: 'index',
        // fixed: 'left',
        // isHidden: true,
        align: 'center',
        width: 60,
        ellipsis: true,
        customRender() {
            return Number(arguments[2]) + 1
        },
    },
    {
        title: '模块名称',
        // width: 80,
        // fixed: 'left',
        align: 'center',
        dataIndex: 'moduleName',
        ellipsis: true,
    },
    {
        title: '用途及所用部位',
        dataIndex: 'usePart',
        align: 'center',
        width: 120,
        // fixed: 'left',
        ellipsis: true,
    },
    {
        title: '软硬件名称',
        width: 100,
        align: 'center',
        dataIndex: 'productName',
        ellipsis: true,
    },
    {
        title: '品牌',
        width: 80,
        dataIndex: 'brandName',
        ellipsis: true,
    },
    {
        title: '规格型号及技术参数',
        dataIndex: 'specification',
        width: 140,
        ellipsis: true,
    },
    {
        title: '单位',
        dataIndex: 'unitName',
        width: 80,
        align: 'center',
        ellipsis: true,
    },
    {
        title: '数量',
        dataIndex: 'productCount',
        width: 80,
        align: 'center',
        ellipsis: true,
    },
    {
        title: '单价(元)',
        width: 120,
        align: 'center',
        dataIndex: 'unitPrice',
        ellipsis: true,
    },
    {
        title: '总价(元)',
        width: 120,
        align: 'center',
        dataIndex: 'totalPrice',
        ellipsis: true,
    },
    {
        title: '资产属性',
        dataIndex: 'assetNature',
        width: 140,
        align: 'center',
        ellipsis: true,
        type: 'select',
        data: [...assetNatureMap.keys()].map((key) => {
            return {
                value: key,
                label: assetNatureMap.get(key)
            }
        }),
        options: [...assetNatureMap.keys()].map((key) => {
            return assetNatureMap.get(key)
        }),
        scopedSlots: {customRender: 'assetNature'},
        excelConfig: {
            dataValidation: {
                type: 'list'
            }
        }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        fixed: 'right',
        isHidden: true,
        align: 'center',
        width: 120,
        ellipsis: true,
        scopedSlots: {customRender: 'operation'}
    }
]

// 资产管理搜索
export const searchManageArr = [
    {
        name: '资产状态',
        value: 'assetStatus',
        type: 'selectMode',
        data: assetStatus,
        attrs:{
            refs: 'assetStatus',
            defaultValue:["0","1","2"]//默认在用、闲置待定
        }
    },
    {
        name: '使用项目',
        valueKey: 'currentOrg',
        type: OrgTreeSelect,
        isNeedAuth: false
    },
    {
        name: '所属单位',
        valueKey: 'ownerOrg',
        type: OrgTreeSelect,
        isNeedAuth: false
    },
    {
        name: '资产编号',
        value: 'assetNumber',
        type: 'input'
    },
    {
        name: '资产名称',
        value: 'assetName',
        type: 'input'
    },
    {
        name: '购买类别',
        value: 'buyCatalogue',
        type: 'select',
        data: buyCatalogue
    },
    {
        name: '预调拨项目',
        value: 'nextOrg',
        valueKey: 'nextOrg',
        type: OrgTreeSelect,
        isNeedAuth: false
    },
    {
        name: '供应商',
        value: 'supplierName',
        type: 'input'
    },
    {
        name: '品牌',
        value: 'brandName',
        type: 'input'
    },
    {
        name: '资产类别',
        value: 'assetCatalogue',
        type: 'select',
        data: assetCatalogue
    },
    {
        name: '保管人',
        value: 'keeperName',
        type: 'input'
    },
    {
        name: '进场时间',
        value: 'enterTime',
        type: 'dateRangeFormat'
    },
    {
        name: '调拨时间',
        value: 'allotTime',
        type: 'dateRangeFormat'
    },
    {
        name: '报废/丢失时间',
        value: 'discardTime',
        type: 'dateRangeFormat'
    },
    {
        name: '调拨次数',
        value: 'allotCount',
        type: 'rangeInput'
    }
]

export function mapAssetNature(key) {
    return assetNatureMap.get(key) || assetNatureMap.get(key + '') || key
}

export function mapAssetStatus(key) {
    return assetStatusMap.get(key) || assetStatusMap.get(key + '') || key
}

export function mapBuyCatalogue(key) {
    return buyCatalogueMap.get(key) || buyCatalogueMap.get(key + '') || key
}

export function mapAssetCatalogue(key) {
    return assetCatalogueMap.get(key) || assetCatalogueMap.get(key + '') || key
}

export function appendTextDescToQrcode(rootEle,qrCanvas,bottomText = []){
    let qrcodeContent  = rootEle
    let qrTarget = qrCanvas
    //config
    let resolutionMultiple = 1; // 分辨率倍数
    let borderSize = 5 * resolutionMultiple; // 边框留白
    let canvasWidth = 200 * resolutionMultiple; // 图片宽度
    let textMargin = 15  * resolutionMultiple;

    // 判断 参数为空的命名情况
    let text = bottomText // 底部文字
    let fontSize = 18 * resolutionMultiple; // 文字大小

    let canvasHeight = canvasWidth;
    let canvas = document.createElement("canvas");
    if (!canvas.getContext) {
        return
    }
    canvas.width = canvasWidth
    canvas.height = canvasHeight+ (fontSize+textMargin) * (text.length+1)

    let ctx = canvas.getContext("2d");
    ctx.fillStyle = "rgb(255,255,255)"; // 调色(纯白)
    ctx.fillRect(0, 0, canvasWidth, canvasHeight); // 绘制背景

    let qrcodeSize = canvasWidth - borderSize * 2;
    ctx.drawImage(
        qrTarget,
        borderSize,
        borderSize,
        qrcodeSize,
        qrcodeSize
    )// 填充二维码

    ctx.fill() // 填充背景

    ctx.fillStyle = "rgb(0,0,0)"; // 调色(纯黑)
    ctx.font = fontSize + "px Arial"; // 文本大小, 字体
    ctx.textAlign = "left";
    let textStartY = qrcodeSize + borderSize + textMargin
    for (let i = 0; i < text.length; i++) {
        ctx.fillText(
            text[i],
            0,
            textStartY + textMargin*(i+1) + fontSize * (i+1),
            qrcodeSize
        ); // 绘制文本
    }
    return canvas
}

export function createQrcode(value='',elementNode) {
    return new QRCode(elementNode, {
        text: value,
        width: 200,
        height: 200,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    })
}
//资产详情分享页面url
export const shareUrl = 'https://pm.cscecxn.com/share/asset?id='